package com.sc.until;

import java.net.URLEncoder;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 验证码通知短信接口
 * 
 * @ClassName: IndustrySMS
 * @Description: 验证码通知短信接口
 *
 */
public class IndustrySMS {
    private static String operation = "/industrySMS/sendSMS";

    private static String accountSid = Config.ACCOUNT_SID;

    /**
     * 验证码通知短信
     * 
     * @throws JSONException
     */
    public static String execute(String phone) throws JSONException {
        String tmpSmsContent = null;
        String to = phone;
        String random = (int) ((Math.random() * 9 + 1) * 100000) + "";
        String smsContent = "【双臣房产】验证码为" + random + "，请于2分钟内正确输入，您正在修改登录密码，请确认是本人操作。";
        try {
            tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
        } catch (Exception e) {

        }
        String url = Config.BASE_URL + operation;
        String body = "accountSid=" + accountSid + "&to=" + to + "&smsContent=" + tmpSmsContent
                + HttpUtil.createCommonParam();

        // 提交请求
        String result = HttpUtil.post(url, body);

        System.out.println("result:" + System.lineSeparator() + result);

        JSONObject jsonObject = new JSONObject(result);
        String respCode = (String) jsonObject.get("respCode");
        System.out.println("respCode=" + respCode);
        if ("00000".equals(respCode)) {
            return random;
        }
        return null;

    }

    /*
     * public static void main(String[] args) throws JSONException {
     * execute("15327345461"); }
     */
}
